package demo2;

class Shape{
    public void draw(){
        System.out.println("画一个图形！");
    }
}

class Rectangle extends Shape{
    @Override
    public void draw() {
        System.out.println("画一个矩形！");
    }
}

class Triangle extends Shape{
    @Override
    public void draw() {
        System.out.println("画一个三角形！");
    }
}

class Circle extends Shape{
    @Override
    public void draw() {
        System.out.println("画一个圆圈！");
    }
}

public class Test {

    //类的调用者书写的
    public static void drawMap(Shape shape){
        shape.draw();
    }

    public static void main(String[] args) {
        Rectangle rect = new Rectangle();
        Triangle triangle = new Triangle();
        Circle circle = new Circle();
        //以后开发过程中，实现多态这里方法的实参一定是各种子类的引用
        //而不是类似Shape shape = new Rectangle();这种写法
        //除非Shape[] shape = {new Rectangle(),new Triangle(),new Rectangle(),new Triangle(),new Circle()}
        drawMap(rect);
        drawMap(triangle);
        drawMap(circle);
    }





    public static void main1(String[] args) {
        Shape shape = new Rectangle();
        Shape shape1 = new Triangle();
        Shape shape2 = new Circle();
        shape.draw();
        shape1.draw();
        shape2.draw();
    }
}
